package ${package}.project.${moduleName}.controller;

import ${javaBasePackage}.annotation.Resource;
import ${tomcatBasePackage}.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.PostMapping;
import ${package}.project.${moduleName}.entity.${ClassName}Entity;
import ${package}.project.${moduleName}.service.${ClassName}Service;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.zhhb.framework.web.controller.BaseController;
import com.zhhb.framework.web.page.Page;

/**
 * @Description: <#if tableComment!?length gt 0>${tableComment}</#if>
 * @Author: ${author}
 * @Version: ${version}
 * @Date: ${datetime}
 */
@RestController
@RequestMapping("/${modulePath}/${modulePathTail}")
public class ${ClassName}Controller extends BaseController {

    //<#if tableComment!?length gt 0>注入 “${tableComment}” service</#if>
    @Resource
    private ${ClassName}Service ${className}Service;

    private final Logger log = LoggerFactory.getLogger(${ClassName}Controller.class);

    /**
     * @Description: 保存数据
     * @Author: ${author}
     * @Params: [${className}Entity, request]
     * @Return: void
     * @Date: ${datetime}
     */
    @PostMapping("saveData.do")
    public ${ClassName}Entity saveData(${ClassName}Entity ${className}Entity) {
        ${className}Service.add(${className}Entity);
        return ${className}Entity;
    }

    /**
     * @Description: 根据ID获取数据
     * @Author: ${author}
     * @Params: [id, request]
     * @Return: void
     * @Date: ${datetime}
     */
    @PostMapping("getById.do")
    public ${ClassName}Entity getById(Long id) {
        return ${className}Service.getById(id);
    }

    /**
     * @Description: 更新数据
     * @Author: ${author}
     * @Params: [${className}Entity, request]
     * @Return: void
     * @Date: ${datetime}
     */
    @PostMapping("updateData.do")
    public ${ClassName}Entity updateData(${ClassName}Entity ${className}Entity) {
        ${className}Service.update(${className}Entity);
        return ${className}Entity;
    }

    /**
     * @Description: 删除数据
     * @Author: ${author}
     * @Params: [ids, request]
     * @Return: void
     * @Date: ${datetime}
     */
    @PostMapping("deleteData.do")
    public void deleteData(String ids) {
        if (ids == null || "".equals(ids)) {
            return;
        }
        //（把要删除的数据是否可用设置为0不可用）
        ${className}Service.deleteByIdStrArray(ids.split(","));
    }

    /**
     * @Description: 分页查询
     * @Author: ${author}
     * @Params: [page, request]
     * @Return: void
     * @Date: ${datetime}
     */
    @PostMapping("listPage.do")
    public Page<${ClassName}Entity> listPage(Page page, HttpServletRequest request) {
        page.intPageForList(request);
        page.getPd().put("orderBy", "create_Time desc, id desc");
        ${className}Service.getListPage(page);
        return page;
    }
}
